package com.yulongtian.interviewWorks.day20220826;

import java.util.ArrayList;
import java.util.List;
import java.util.Stack;

/**
 * https://leetcode.cn/problems/power-set-lcci/
 *
 * @author YulongTian
 * @date 2022/8/26 - 16:41
 */
public class Test08 {

    public static void main(String[] args) {
        int[] nums = {1,2,3};
        System.out.println(subsets(nums));
    }

    public static List<List<Integer>> subsets(int[] nums) {
        Stack<Integer> visit = new Stack<>();
        List<List<Integer>> res = new ArrayList<>();
        dfs(nums, visit, res, 0);
        res.add(new ArrayList<>());
        return res;
    }

    public static void dfs(int[] nums, Stack<Integer> visit, List<List<Integer>> res, int start) {
        if (start >= nums.length) {
            return;
        }
        for (int i = start; i < nums.length; i++) {
            visit.push(nums[i]);
            res.add(new ArrayList<>(visit));
            dfs(nums, visit, res, i+1);
            visit.pop();
        }

    }

}
